Ball = {}

local BallSpawnPos = Vector(0, 0, 0)
local BallEntity = nil

function Ball.Create()
	BallEntity = ents.Create("dangerous_ball")
	local ballSpawns = ents.FindByName("dangerous_ball_spawn")
	PrintTable(ballSpawns)	
	MsgN("ball entity: " .. tostring(BallEntity));
	for k, v in pairs(ballSpawns) do
		BallSpawnPos = v:GetPos()		
	end
	BallEntity:SetPos(BallSpawnPos)
	BallEntity:Spawn()
	BallEntity:Activate()
	return Ball
end

function Ball.Kick(strength)
	BallEntity:Kick(strength)
end

function Ball.HasOwner()
	return BallEntity:HasBallOwner()
end

function Ball.Clear()
	BallEntity:RemoveBallOwner()
	BallEntity:SetFree()
end

function Ball.IsUnderControl()
	return not BallEntity:IsFree()
end

function Ball.GetOwner()
	return BallEntity:GetBallOwner()
end

function Ball.TeleportToPlayerPosition(ply)
	BallEntity:SetPos(ply:GetPos())
end

hook.Add("Goal", "Ball.OnGoal", function()
	BallEntity:Remove()
end)

hook.Add("RoundStart", "Ball.OnRoundStart", function()
	Ball.Create()
end)